package com.project.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.project.bean.LogBean;
import com.project.bean.UserBean;
import com.project.dao.IUserDao;
import com.project.service.ILogService;
import com.project.service.IUserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.time.LocalTime;
import java.util.List;

/**
 * @author RJ
 * @date 2022/9/14 11:51
 */
@Service
@Transactional
public class UserServiceImpl extends ServiceImpl<IUserDao, UserBean> implements IUserService {

    @Resource
    private ILogService logService;

    @Override
    public UserBean login(String userName, String userPwd) {
        UserBean userBean = this.baseMapper.login(userName, userPwd);
        if(userBean != null){
            /*String info = "用户" + userName +
                    "在" + LocalTime.now().toString().substring(0,5) + "登陆系统";
            logService.addLog(new LogBean(info));*/
        }
        return userBean;
    }

    @Override
    public void addUser(UserBean user) {
        this.save(user);
    }

    @Override
    public void delUser(Integer userId) {
        this.removeById(userId);
    }

    @Override
    public void updUser(Integer userId, String userPwd, String userGrade) {
        this.baseMapper.updUser(userId, userPwd, userGrade);
    }

    @Override
    public IPage<UserBean> cutUsersByGrade(Integer pageNo, Integer pageSize, String userGrade) {
        Page<UserBean> page = new Page<>(pageNo, pageSize);
        IPage<UserBean> iPage = this.baseMapper.cutUsersByGrade(page, userGrade);
        return iPage;
    }
}
